//
//  TaskDiaoDuOrderGoodCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/4/2.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "TaskDiaoDuOrderGoodCell.h"

@interface TaskDiaoDuOrderGoodCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *title1Lab;
@property (nonatomic, strong) UILabel *content1Lab;
@property (nonatomic, strong) UILabel *title2Lab;
@property (nonatomic, strong) UILabel *content2Lab;
@property (nonatomic, strong) UILabel *title3Lab;
@property (nonatomic, strong) UILabel *content3Lab;
@property (nonatomic, strong) UILabel *title4Lab;
@property (nonatomic, strong) UILabel *content4Lab;
@property (nonatomic, strong) UILabel *title5Lab;
@property (nonatomic, strong) UILabel *content5Lab;
@property (nonatomic, strong) UILabel *title6Lab;
@property (nonatomic, strong) UILabel *content6Lab;
@property (nonatomic, strong) UILabel *pieceTitleLab;
@property (nonatomic, strong) UITextField *pieceField;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UITextField *countField;
@property (nonatomic, strong) UILabel *weightTitleLab;
@property (nonatomic, strong) UITextField *weightField;
@property (nonatomic, strong) UILabel *volumeTitleLab;
@property (nonatomic, strong) UITextField *volumeField;

@end

@implementation TaskDiaoDuOrderGoodCell

+ (instancetype)TaskDiaoDuOrderGoodCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TaskDiaoDuOrderGoodCell";
    TaskDiaoDuOrderGoodCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TaskDiaoDuOrderGoodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = Color_backgroundColor;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.font = BoldFontOfSize(18);
        self.titleLab.textColor = HexColor(0x2B2C44);
        [self.bgView addSubview:self.titleLab];
        
        self.title1Lab = [UILabel new];
        self.title1Lab.textColor = HexColor(0x9C9DB3);
        self.title1Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.title1Lab];
        
        self.content1Lab = [UILabel new];
        self.content1Lab.textColor = HexColor(0x2B2C44);
        self.content1Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.content1Lab];
        
        self.title2Lab = [UILabel new];
        self.title2Lab.textColor = HexColor(0x9C9DB3);
        self.title2Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.title2Lab];
        
        self.content2Lab = [UILabel new];
        self.content2Lab.textColor = HexColor(0x2B2C44);
        self.content2Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.content2Lab];
        
        self.title3Lab = [UILabel new];
        self.title3Lab.textColor = HexColor(0x9C9DB3);
        self.title3Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.title3Lab];
        
        self.content3Lab = [UILabel new];
        self.content3Lab.textColor = HexColor(0x2B2C44);
        self.content3Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.content3Lab];
        
        self.title4Lab = [UILabel new];
        self.title4Lab.textColor = HexColor(0x9C9DB3);
        self.title4Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.title4Lab];
        
        self.content4Lab = [UILabel new];
        self.content4Lab.textColor = HexColor(0x2B2C44);
        self.content4Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.content4Lab];
        
        self.title5Lab = [UILabel new];
        self.title5Lab.textColor = HexColor(0x9C9DB3);
        self.title5Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.title5Lab];
        
        self.content5Lab = [UILabel new];
        self.content5Lab.textColor = HexColor(0x2B2C44);
        self.content5Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.content5Lab];
        
        self.title6Lab = [UILabel new];
        self.title6Lab.textColor = HexColor(0x9C9DB3);
        self.title6Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.title6Lab];
        
        self.content6Lab = [UILabel new];
        self.content6Lab.textColor = HexColor(0x2B2C44);
        self.content6Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.content6Lab];
        
        self.pieceTitleLab = [UILabel new];
        self.pieceTitleLab.textColor = Color_ThemeColor;
        self.pieceTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.pieceTitleLab];
        
        self.pieceField = [UITextField new];
        self.pieceField.font = [UIFont systemFontOfSize:14];
        self.pieceField.backgroundColor = HexColor(0xF6F6F6);
        self.pieceField.layer.masksToBounds = YES;
        self.pieceField.layer.cornerRadius = 2;
        self.pieceField.textColor = HexColor(0x000000);
        self.pieceField.textAlignment = NSTextAlignmentCenter;
        self.pieceField.keyboardType = UIKeyboardTypeNumberPad;
        self.pieceField.placeholder = @"件数";
        [self.pieceField addTarget:self action:@selector(pieceFieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.pieceField];
        
        self.countTitleLab = [UILabel new];
        self.countTitleLab.textColor = Color_ThemeColor;
        self.countTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countTitleLab];
        
        self.countField = [UITextField new];
        self.countField.font = [UIFont systemFontOfSize:14];
        self.countField.backgroundColor = HexColor(0xF6F6F6);
        self.countField.layer.masksToBounds = YES;
        self.countField.layer.cornerRadius = 2;
        self.countField.textColor = HexColor(0x000000);
        self.countField.textAlignment = NSTextAlignmentCenter;
        self.countField.keyboardType = UIKeyboardTypeNumberPad;
        self.countField.placeholder = @"数量";
        [self.countField addTarget:self action:@selector(countFieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.countField];
        
        self.weightTitleLab = [UILabel new];
        self.weightTitleLab.textColor = Color_ThemeColor;
        self.weightTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.weightTitleLab];
        
        self.weightField = [UITextField new];
        self.weightField.font = [UIFont systemFontOfSize:14];
        self.weightField.backgroundColor = HexColor(0xF6F6F6);
        self.weightField.layer.masksToBounds = YES;
        self.weightField.layer.cornerRadius = 2;
        self.weightField.textColor = HexColor(0x000000);
        self.weightField.textAlignment = NSTextAlignmentCenter;
        self.weightField.keyboardType = UIKeyboardTypeDecimalPad;
        self.weightField.placeholder = @"重量";
        [self.weightField addTarget:self action:@selector(weightFieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.weightField];
        
        self.volumeTitleLab = [UILabel new];
        self.volumeTitleLab.textColor = Color_ThemeColor;
        self.volumeTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.volumeTitleLab];
        
        self.volumeField = [UITextField new];
        self.volumeField.font = [UIFont systemFontOfSize:14];
        self.volumeField.backgroundColor = HexColor(0xF6F6F6);
        self.volumeField.layer.masksToBounds = YES;
        self.volumeField.layer.cornerRadius = 2;
        self.volumeField.textColor = HexColor(0x000000);
        self.volumeField.textAlignment = NSTextAlignmentCenter;
        self.volumeField.keyboardType = UIKeyboardTypeDecimalPad;
        self.volumeField.placeholder = @"体积";
        [self.volumeField addTarget:self action:@selector(volumeFieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.volumeField];
    }
    return self;
}

- (void)pieceFieldTextChanged:(UITextField *)field {
    if (self.pnumBlock) {
        self.pnumBlock(field.text);
    }
}

- (void)countFieldTextChanged:(UITextField *)field {
    if (self.countBlock) {
        self.countBlock(field.text);
    }
}

- (void)weightFieldTextChanged:(UITextField *)field {
    if (self.weightBlock) {
        self.weightBlock(field.text);
    }
}

- (void)volumeFieldTextChanged:(UITextField *)field {
    if (self.volumeBlock) {
        self.volumeBlock(field.text);
    }
}

-(void)setModel:(TaskDiaoDuOrderGoodModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    self.titleLab.frame = CGRectMake(15, 15, self.bgView.nim_width - 30, 19);
    self.titleLab.text = [NSString stringWithFormat:@"货物名称：%@",self.model.goods_name];
    
    self.title1Lab.text = @"型号：";
    [self.title1Lab sizeToFit];
    self.title1Lab.nim_left = self.titleLab.nim_left;
    self.title1Lab.nim_top = self.titleLab.nim_bottom + 10;
    
    self.title2Lab.text = @"包装：";
    [self.title2Lab sizeToFit];
    self.title2Lab.nim_left = self.bgView.nim_width * 0.5;
    self.title2Lab.nim_top = self.title1Lab.nim_top;
    
    self.title3Lab.text = @"货物件数：";
    [self.title3Lab sizeToFit];
    self.title3Lab.nim_left = self.title1Lab.nim_left;
    self.title3Lab.nim_top = self.title1Lab.nim_bottom + 10;
    
    self.title4Lab.text = @"货物数量：";
    [self.title4Lab sizeToFit];
    self.title4Lab.nim_left = self.title2Lab.nim_left;
    self.title4Lab.nim_top = self.title3Lab.nim_top;
    
    self.content1Lab.frame = CGRectMake(self.title1Lab.nim_right, self.title1Lab.nim_top, self.title2Lab.nim_left - self.title1Lab.nim_right, self.title1Lab.nim_height);
    self.content2Lab.frame = CGRectMake(self.title2Lab.nim_right, self.title2Lab.nim_top, self.bgView.nim_width - 15 - self.title2Lab.nim_right, self.title2Lab.nim_height);
    self.content3Lab.frame = CGRectMake(self.title3Lab.nim_right, self.title3Lab.nim_top, self.title4Lab.nim_left - self.title3Lab.nim_right, self.title3Lab.nim_height);
    self.content4Lab.frame = CGRectMake(self.title4Lab.nim_right, self.title4Lab.nim_top, self.bgView.nim_width - 15 - self.title4Lab.nim_right, self.title4Lab.nim_height);
    
    self.pieceTitleLab.text = @"装载件数：";
    [self.pieceTitleLab sizeToFit];
    self.pieceTitleLab.nim_left = self.title1Lab.nim_left;
    self.pieceTitleLab.nim_top = self.title3Lab.nim_bottom + 10;
    
    self.pieceField.nim_left = self.pieceTitleLab.nim_right;
    self.pieceField.nim_width = 74;
    self.pieceField.nim_height = 25;
    self.pieceField.nim_centerY = self.pieceTitleLab.nim_centerY;
    
    self.countTitleLab.text = @"装载数量：";
    [self.countTitleLab sizeToFit];
    self.countTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.countTitleLab.nim_top = self.pieceTitleLab.nim_top;
    
    self.countField.nim_left = self.countTitleLab.nim_right;
    self.countField.nim_width = 74;
    self.countField.nim_height = 25;
    self.countField.nim_centerY = self.countTitleLab.nim_centerY;
    
    self.title5Lab.text = @"货物重量：";
    [self.title5Lab sizeToFit];
    self.title5Lab.nim_left = self.title1Lab.nim_left;
    self.title5Lab.nim_top = self.pieceTitleLab.nim_bottom + 10;
    
    self.title6Lab.text = @"货物体积：";
    [self.title6Lab sizeToFit];
    self.title6Lab.nim_left = self.title2Lab.nim_left;
    self.title6Lab.nim_top = self.title5Lab.nim_top;
    
    self.content5Lab.frame = CGRectMake(self.title5Lab.nim_right, self.title5Lab.nim_top, self.title6Lab.nim_left - self.title5Lab.nim_right, self.title5Lab.nim_height);
    self.content6Lab.frame = CGRectMake(self.title6Lab.nim_right, self.title6Lab.nim_top, self.bgView.nim_width - 15 - self.title6Lab.nim_right, self.title6Lab.nim_height);
    
    self.weightTitleLab.text = @"装载重量：";
    [self.weightTitleLab sizeToFit];
    self.weightTitleLab.nim_left = self.title1Lab.nim_left;
    self.weightTitleLab.nim_top = self.title5Lab.nim_bottom + 10;
    
    self.weightField.nim_left = self.weightTitleLab.nim_right;
    self.weightField.nim_width = 74;
    self.weightField.nim_height = 25;
    self.weightField.nim_centerY = self.weightTitleLab.nim_centerY;
    
    self.volumeTitleLab.text = @"装载体积：";
    [self.volumeTitleLab sizeToFit];
    self.volumeTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.volumeTitleLab.nim_top = self.weightTitleLab.nim_top;
    
    self.volumeField.nim_left = self.volumeTitleLab.nim_right;
    self.volumeField.nim_width = 74;
    self.volumeField.nim_height = 25;
    self.volumeField.nim_centerY = self.volumeTitleLab.nim_centerY;
    
    self.bgView.nim_height = self.volumeTitleLab.nim_bottom + 20;
    
    self.height = self.bgView.nim_bottom;
    
    
    
    self.content1Lab.text = self.model.good_type;
    self.content2Lab.text = self.model.pk_name;
    self.content3Lab.text = [NSString stringWithFormat:@"%d",self.model.pnum];
    self.content4Lab.text = [NSString stringWithFormat:@"%d",self.model.num];
    
    self.pieceField.text = self.model.select_pnum ? [NSString stringWithFormat:@"%d",self.model.select_pnum] : @"";
    self.countField.text = self.model.select_num ? [NSString stringWithFormat:@"%d",self.model.select_num] : @"";
    
    self.content5Lab.text = self.model.residue_weight ? [NSString stringWithFormat:@"%@KG",[FactoryMethod removerNumberWithZero:[NSString stringWithFormat:@"%.2f",self.model.residue_weight]]] : @"--KG";
    self.content6Lab.text = self.model.residue_volume ? [NSString stringWithFormat:@"%@m³",[FactoryMethod removerNumberWithZero:[NSString stringWithFormat:@"%.2f",self.model.residue_volume]]] : @"--m³";
    
    self.weightField.text = self.model.select_weight ? [NSString stringWithFormat:@"%@",[FactoryMethod removerNumberWithZero:[NSString stringWithFormat:@"%.2f",self.model.select_weight]]] : @"";
    self.volumeField.text = self.model.select_volume ? [NSString stringWithFormat:@"%@",[FactoryMethod removerNumberWithZero:[NSString stringWithFormat:@"%.2f",self.model.select_volume]]] : @"";
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
